<%@ page language="java" pageEncoding="UTF-8" %>
<%@ include file="/common/taglibs.jsp"%>
<%@ include file="/common/popup/head.jsp"%>

<script type="text/javascript" src="<s:property value="ctx"/>/js/jstree/jquery.jstree.js"></script>

<script type="text/javascript">

	function clickBtn(action){
		switch(action){
		case "saveIntoTrolley":
			  CE.close();
			  return;
			  
		case "back":
			  CE.close();
			  return;
		}

		$("#mainForm").submit();  
	}

	$(function () {
		$("#areaTree").jstree({
			    "themes" : {"theme" : "apple",
							"dots" : true,
							"icons" : true
		                },		 
				"plugins" : ["themes","html_data","ui"]
		});

		$("#tradeTree").jstree({
		    "themes" : {"theme" : "default",
						"dots" : true,
						"icons" : true
	                    },	
					
			"plugins" : ["themes","html_data","ui"]
		});		

	});	
	
	
	function clickArea(clickedAreaId,clickedAreaName){
		
		displayArea(clickedAreaId,clickedAreaName)
		
		//3. 加载地理树
		$("#areaTree").jstree({
		    "themes" : {"theme" : "apple",
						"dots" : true,
						"icons" : true
	                   },
			"html_data" : {"ajax" : {url   : "area-trade-tree!ajaxGetAreaTree.action?clickedAreaId="+clickedAreaId,
									 cache : true,
									 async : false
									 }
					     },		
			"core" : {"initially_open" : [clickedAreaId]},  
			"ui":{"initially_select" : [clickedAreaId]},				     
			"plugins" : ["themes","html_data","ui"]
		});
	}
	
	function displayArea(clickedAreaId,clickedAreaName){
		//1. 修改父页面地理字段
		$('#areaId', window.parent.document).val(clickedAreaId);
		$('#areaName', window.parent.document).html(clickedAreaName);
		
		
		//2. 加载父页面地理微调字段
		$.ajax({
			url : "area-trade-tree!ajaxGetAdjustAreas.action?clickedAreaId="+clickedAreaId,
			cache : true,
			dataType : "json",
			async : false,
			success : function(adjustAreas) {
				if(adjustAreas.lenght==0){
					return;
				}
				
				$("#adjustArea",window.parent.document).empty();
				
				$("#adjustArea",window.parent.document).append("<option value=''>-All-</option>");
				
				$.each(adjustAreas, function(i, adjustArea) {
					$("#adjustArea",window.parent.document).append(
							"<option value='"+adjustArea.code+"'>" + adjustArea.desc + "</option>");
				})
			},
			error : function(data) {
				$("#errorMsgSpan").html(data);
			}
		});		
		
	}
	
	function clickTrade(clickedTradeId,clickedTradeName){
		
		displayTrade(clickedTradeId,clickedTradeName)
		
		//3. 加载行业树
		$("#tradeTree").jstree({
		    "themes" : {"theme" : "default",
						"dots" : true,
						"icons" : true
	                   },
     		"html_data" : {"ajax" : {url   : "area-trade-tree!ajaxGetTradeTree.action?clickedTradeId="+clickedTradeId,
									 cache : true,
					 				 async : false
			 			            }
		                  },		
			"core" : {"initially_open" : [clickedTradeId]},  
			"ui":{"initially_select" : [clickedTradeId]},	     
			"plugins" : ["themes","html_data","ui"]
		});			
	}	
	
	function displayTrade(clickedTradeId,clickedTradeName){
		//1. 修改父页面行业字段
		$('#tradeId', window.parent.document).val(clickedTradeId);
		$('#tradeName', window.parent.document).html(clickedTradeName);
		
		//2. 加载父页面行业微调字段
		$.ajax({
			url : "area-trade-tree!ajaxGetAdjustTrades.action?clickedTradeId="+clickedTradeId,
			cache : true,
			dataType : "json",
			async : false,
			success : function(adjustTrades) {
				if(adjustTrades.lenght==0){
					return;
				}
				
				$("#adjustTrade",window.parent.document).empty();
				$("#adjustTrade",window.parent.document).append("<option value=''>-All-</option>");
				
				$.each(adjustTrades, function(i, adjustTrade) {
					$("#adjustTrade",window.parent.document).append(
							"<option value='"+adjustTrade.code+"'>" + adjustTrade.desc + "</option>");
				})
			},
			error : function(data) {
				$("#errorMsgSpan").html(data);
			}
		});			
	}
</script>

	  
 <table id="areaTradeTreeDiv" cellspacing="0" cellpadding="0" border="0">
     <tbody>
   <tr>
     <td height="30px">&nbsp;</td>
   </tr>	      
   <tr>
     <td>

		<div id="areaTree" class="tree">
		   <s:property value="areaTreeData" escapeHtml="false"/>
		</div>

	</td>
   </tr>
   <tr>
     <td height="30px">&nbsp;</td>
   </tr>
   <tr>
     <td>
		<div id="tradeTree" class="tree">
			<s:property value="tradeTreeData" escapeHtml="false"/>
		</div>
     </td>
   </tr>	
   </tbody>      	      
</table>
			    
<%@ include file="/common/popup/foot.jsp"%>  